import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.concurrent.Callable;

public class ReadTask implements Callable<byte[]> {

    private File fileToRead;
    /**
     * Количество байт, которые должен считать данный поток
     */
    private int numberOfBytesToRead;

    /**
     * Смещение
     */
    private long offset;

    public ReadTask(File fileToRead, int numberOfBytesToRead, long offset) {
        this.fileToRead = fileToRead;
        this.numberOfBytesToRead = numberOfBytesToRead;
        this.offset = offset;
    }

    @Override
    public byte[] call() throws Exception {
        byte[] result = new byte[numberOfBytesToRead];
        InputStream is = new BufferedInputStream(new FileInputStream(fileToRead), numberOfBytesToRead);
        is.skip(offset);
        is.read(result);
        return result;
    }
}
